package com.shopping.utils;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * 生成订单编号工具类
 */
public class GenerateOrderId {


    private static int num=0;
    private static final int MIN_NUM=0;
    private static final int MAX_NUM=10000000;

    public static synchronized String getOrderId(){
        String timeStr =new SimpleDateFormat("yyyyMMddHHmmssSS").format(new Date());
        if (num>=MAX_NUM){
            num=MIN_NUM;
        }
        String orderId =timeStr+num;

        try {
            TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {

        }
        num++;
        return orderId;
    }
}
